<?php
/**
 * ============================================================================
 * Copyright (c) 2015-2019 贵州大师兄信息技术有限公司 All rights reserved.
 * siteַ: https://www.gzdsx.cn
 * ============================================================================
 * @author:     David Song<songdewei@163.com>
 * @version:    v1.0.0
 * ---------------------------------------------
 * Date: 2020-06-07
 * Time: 15:22
 */


/**
 * @param $streamName
 * @param null $time
 * @return string
 */
function getLivePushUrl($streamName, $time = null)
{
    if ($streamName && $time) {
        $txTime = strtoupper(base_convert($time, 10, 16));
        $txSecret = md5(config('live.push_key') . $streamName . $txTime);
        $ext_str = "?" . http_build_query([
                "txSecret" => $txSecret,
                "txTime" => $txTime
            ]);
    }
    return config('live.push_url') . "/" . $streamName . (isset($ext_str) ? $ext_str : "");
}

/**
 * @param $streamName
 * @param null $time
 * @return string
 */
function getLivePlayUrl($streamName, $time = null, $type = 'hls')
{
    if ($streamName && $time) {
        $txTime = strtoupper(base_convert($time, 10, 16));
        $txSecret = md5(config('live.play_key') . $streamName . $txTime);
        $ext_str = "?" . http_build_query([
                "txSecret" => $txSecret,
                "txTime" => $txTime
            ]);
    }

    if ($type == 'flv') {
        $ext = '.flv';
    } elseif ($type == 'hls') {
        $ext = '.m3u8';
    } else {
        $ext = '';
    }
    return config('live.play_url') . "/" . $streamName . $ext . (isset($ext_str) ? $ext_str : "");
}
